package com.fpx.metadata.controller;

import com.fpx.metadata.bean.po.DbInfo;
import com.fpx.metadata.bean.po.User;
import com.fpx.metadata.service.UserService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
@Api(value = "用户", description = "用户")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "登录", notes = "登录")
    @PostMapping("login")
    public String login(User user) {
        return userService.login(user) ? "succese" : "error";
    }

    @ApiOperation(value="分页查询", notes = "分页查询")
    @GetMapping("queryListByPage/v1/{page}/{rows}")
    public PageInfo<User> queryListByPage(@PathVariable Integer page, @PathVariable Integer rows) {
        return userService.queryPageListByWhere(null, page, rows);
    }

    @ApiOperation(value="根据ID查询", notes = "根据ID查询")
    @GetMapping("queryById/{id}")
    public User queryById(@PathVariable Long id) {
        return userService.queryById(id);
    }

    @ApiOperation(value="保存", notes = "保存")
    @PostMapping("save")
    public String save(User dbInfo) {
        return userService.saveSelect(dbInfo) > 0 ? "succese" : "error";
    }

    @ApiOperation(value="更新", notes = "更新")
    @PutMapping("udpate")
    public String update(User dbInfo) {
        return userService.updateSelective(dbInfo) > 0 ? "succese" : "error";
    }
}
